<?php
/**
 * Permet la création des selects propres au site
 */

if(!function_exists('dropdown_type_competition'))
{
	function dropdown_type_competition($input_name, $from_var, $label, $error)
	{
		$CI =& get_instance();
		$options = array("" => "Sélectionner un type de compétition");
		$options += $CI->config->item('types_competition', 'my_site');
		return my_form_dropdown($input_name, $options, $from_var, $label, $error);
	}
}

if(!function_exists('dropdown_time'))
{
	function dropdown_time($input_name, $from_var, $label, $error)
	{
		return dropdown_hour($input_name[0], $from_var, $label, $error).
			 dropdown_minutes($input_name[1], $from_var, $label, $error);
	}
}

if(!function_exists('dropdown_hour'))
{
	function dropdown_hour($input_name, $from_var, $label, $error)
	{
		$CI =& get_instance();
		$options = array();
		for($i=0; $i<24; $i++) {
			$options[$i] = str_pad($i, 2, "0", STR_PAD_LEFT)."h";
		}
		return my_form_dropdown($input_name, $options, $from_var, $label, $error);
	}
}

if(!function_exists('dropdown_minutes'))
{
	function dropdown_minutes($input_name, $from_var, $label, $error)
	{
		$CI =& get_instance();
		$options = array();
		for($i=0; $i<60; $i+=5) {
			$options[$i] = str_pad($i, 2, "0", STR_PAD_LEFT)."m";
		}
		return my_form_dropdown($input_name, $options, $from_var, $label, $error);
	}
}

if(!function_exists('dropdown_team'))
{
	function dropdown_team($input_name, $from_var, $label, $error, $teams)
	{
		$options = array("" => "Sélectionner une équipe");
		foreach ($teams as $team) {
			$options[$team->id] = $team->team_name;
		}
		return my_form_dropdown($input_name, $options, $from_var, $label, $error);
	}
}

if(!function_exists('dropdown_flags'))
{
	function dropdown_flags($input_name, $from_var, $label, $error)
	{
		$CI =& get_instance();
		$value = null;
		if(is_object($from_var) && isset($from_var->{$input_name})) {
			$value = $from_var->{$input_name};
		}
		$html = '';
		for($i=1; $i<240; $i++) {
			$html .= '<div class="select_flags select_flag'.$i.' '.
						($i == $value ? 'flag_check' : '').'">'.
					'<div class="input_flag">'.
					'<input type="radio" name="'.$input_name.'" value="'.$i.'"'.
					' '.($i == $value ? 'checked' : '').' '.
					'/></div><div class="flags flag'.$i.'"></div>'.
				'</div>';
		}
		return $html;
	}
}